package com.abss.vote.mapper;

import com.abss.vote.model.*;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface ActivityMapper {

    Activity getActivityId(int ACTIVITY_ID);

    ActivityPrizeVo getPrize1(int ACTIVITY_ID);
    ActivityPrizeVo getPrize2(int ACTIVITY_ID);
    ActivityPrizeVo getPrize3(int ACTIVITY_ID);

    int setVisist(int ACTIVITY_ID);

    int setVoteNumber(@Param("ACTIVITY_ID") int ACTIVITY_ID);

    String getActivityName(int ACTIVITY_ID);

    int getLeftVotes(@Param("activity_id") int activity_id);//将该活动设置的点赞次数查出

    List<Activity> getAllActivity();

    List<Activity> getActivityByStateAndName(@Param("name") String name,@Param("state") String state);
    List<Activity> getActivityByStateAndNamelocalServer(@Param("name") String name,@Param("state") String state,@Param("server_id") String server_id,@Param("admin") String admin);
    List<Activity> getActivityByStateAndNames(@Param("name") String name,@Param("state") String state,@Param("server_id") String server_id);

    int addActivity(Activity activity);

    Activity getActivityById(int ACTIVITY_ID);

    int updateActivityById(Activity activity);

    int updateActivityDetailsById(Activity activity);

    int updateAc(Activity activity);
    int updateQrcode(Activity activity);
    List<Activity> getActivityBySth();

    Activity getActivitySelect(int ACTIVITY_ID);

    int updateActivityStateById(@Param("ACTIVITY_STATE")String ACTIVITY_STATE, @Param("ACTIVITY_ID")int ACTIVITY_ID);

    int checkActivityByid(int ACTIVITY_ID);
    int checkActivityByids(@Param("ACTIVITY_ID")int ACTIVITY_ID,@Param("ACTIVITY_ID")String server_id);

    int getNewAvtivityId();

    ActivityPrizeVo getActivityDetails(int ACTIVITY_ID);

    int addActivityVotesNum( @Param("ACTIVITY_ID") int ACTIVITY_ID);

    List<Activity> getActivit(@Param("start")int start,@Param("end") int end,@Param("ServerId") String ServerId);
    List<Activity> getActivits(@Param("start")int start,@Param("end") int end);
    List<Activity> getActivitss(@Param("start")int start,@Param("end") int end,@Param("admin") String admin);

    /**
     * 更新所有的活动状态
     * @return
     */
    @Update("UPDATE ACTIVITY SET ACTIVITY_STATE = ( CASE  WHEN ACTIVITY_STARTTIME > getdate()  THEN  '0'  WHEN ACTIVITY_ENDTIME  < getdate() THEN '2'  ELSE '1' END )")
    Integer updateActivityState();

    @Select("select p.* from ACTIVITY a inner join PRIZE p on a.PRIZE1_ID=p.PRIZE_ID where a.ACTIVITY_ID=${activity_id}")
    Prize getPrize1Info(@Param("activity_id") int activity_id);

    @Select("select p.* from ACTIVITY a inner join PRIZE p on a.PRIZE2_ID=p.PRIZE_ID where a.ACTIVITY_ID=${activity_id}")
    Prize getPrize2Info(@Param("activity_id") int activity_id);

    @Select("select p.* from ACTIVITY a inner join PRIZE p on a.PRIZE3_ID=p.PRIZE_ID where a.ACTIVITY_ID=${activity_id}")
    Prize getPrize3Info(@Param("activity_id") int activity_id);

    int getVotesLimitTosinglePerday(int activity_id);

    int setIsOpenYdcp(@Param("is_open_ydcp") int is_open_ydcp, @Param("ACTIVITY_ID") int ACTIVITY_ID);

    int setYdcpNum(@Param("ydcp_num") int ydcp_num, @Param("ACTIVITY_ID") int ACTIVITY_ID);

    int setOrderRule(@Param("order_rule") int order_rule, @Param("ACTIVITY_ID") int ACTIVITY_ID);

    int deptUpdate(Activity activity);
    
    int groupRuleUpdate(Activity activity);

    int setIsVote(@Param("is_vote") int is_vote,@Param("ACTIVITY_ID") int ACTIVITY_ID);

    int setWorkNumber(@Param("works_limit_peruser") int works_limit_peruser,@Param("activity_id") int activity_id);

    int setVotesLinitPerday(@Param("votes_limit_perday") int votes_limit_perday,@Param("activity_id") int activity_id);

    int setVotesLimitTosinglePerday(@Param("votes_limit_tosingle_perday") int votes_limit_tosingle_perday,@Param("activity_id") int activity_id);

    int setCurrentStage(@Param("current_stage") int current_stage,@Param("activity_id") int activity_id);

    int setWorkType(@Param("work_type") int work_type, @Param("activity_id") int activity_id);

    int setEntryTime(Activity activity);
    int setIsSigup(@Param("is_sigup") int is_sigup,@Param("activity_id") int activity_id);

    int setSubmitWorkNumber(@Param("submit_work_number") int submit_work_number,@Param("activity_id") int activity_id);

    @Select("select SUBMIT_WORK_NUMBER from ACTIVITY where ACTIVITY_ID=${activity_id}")
    int getSubmitWorkNumber(@Param("activity_id") int activity_id);

    int getCountNumber(@Param("activity_id") int activity_id,@Param("disID") int disID);

    int getCurrentStage(int activity_id);

    int setDELETED(@Param("deleted") int deleted,@Param("activity_id") int activity_id);

    int setACTIVITY_STATE(@Param("activity_state") int activity_state, @Param("activity_id") int activity_id);

    int setIS_IN(@Param("is_in") int is_in, @Param("activity_id") int activity_id);
    
    int setIS_SHOW_COMMENT(@Param("is_show_comment") int is_show_comment, @Param("activity_id") int activity_id);

    int deleteActivity(@Param("activity_id") String activity_id);

    @Select("select * from ACTIVITY where ACTIVITY_ID=${activity_id}")
    Activity getNumber(@Param("activity_id") int activity_id);


    @Update("update ACTIVITY set ACTIVITY_WIN=#{activity_win} where ACTIVITY_ID=#{activity_id}")
    int setACTIVITY_WIN(@Param("activity_id") int activity_id,@Param("activity_win") int activity_win);


    int updateTime(Activity activity);

    @Select("select * from ACTIVITY where REMOVE=0")
    List<Activity> getActivityNoDeled();

    @Update("update ACTIVITY set ACTIVITY_VISIST=#{activity_visist} where ACTIVITY_ID=#{activity_id}")
    int setACTIVITY_VISIST(@Param("activity_id") Integer activityId,@Param("activity_visist") Integer activity_visist);
    @Update("update ACTIVITY set REG_USER=#{reg_user} where ACTIVITY_ID=#{activity_id}")
    int setREG_USER(@Param("activity_id") Integer activityId,@Param("reg_user") Integer reg_user);
    @Update("update ACTIVITY set VOTES_USER=#{votes_user} where ACTIVITY_ID=#{activity_id}")
    int setVOTES_USER(@Param("activity_id") String activityId,@Param("votes_user") Integer votes_user);
    @Update("update ACTIVITY set VOTES_NUMBER=#{votes_number} where ACTIVITY_ID=#{activity_id}")
    int setVOTES_NUMBER(@Param("activity_id") Integer activityId,@Param("votes_number") Integer votes_number);
    @Update("update ACTIVITY set VOTES_LIMIT_PERDAY=#{votes_limit_perday} where ACTIVITY_ID=#{activity_id}")
    int setVOTES_LIMIT_PERDAY(@Param("activity_id") Integer activityId,@Param("votes_limit_perday") Integer votes_limit_perday);
    @Update("update ACTIVITY set VOTES_LIMIT_TOSINGLE_PERDAY=#{votes_limit_tosingle_perday} where ACTIVITY_ID=#{activity_id}")
    int setVOTES_LIMIT_TOSINGLE_PERDAY(@Param("activity_id") Integer activityId,@Param("votes_limit_tosingle_perday") Integer votes_limit_tosingle_perday);
    @Update("update ACTIVITY set IS_SUBMIT=#{is_submit} where ACTIVITY_ID=#{activity_id}")
    int setSubmit(@Param("is_submit")int is_submit,@Param("activity_id") int activity_id);
    @Update("update ACTIVITY set WINNERS=#{winners} where ACTIVITY_ID=#{activity_id}")
    int setWINNERS(@Param("winners")int winners,@Param("activity_id") int activity_id);


    List<Activity> getAllActivitiesNoRemove();
    List<Activity> getAllActivitiesNoRemoves(@Param("server_id")String server_id);
    List<Activity> getAllActivitiesNoRemovess(@Param("server_id")String server_id,@Param("admin")String admin);

    int getActivityAdminId(int id);

    int deleteActivityByAdminAccount(@Param("admin_account") String admin_account);

    String getActivityServerId(@Param("activity_id") int activity_id);


    int updateActivityRules(Activity activity);

    @Update("update ACTIVITY set IS_ROTE=#{is_rote} where ACTIVITY_ID=#{activity_id}")
    int setIsRote(@Param("is_rote") int is_rote,@Param("activity_id")  int activity_id);

    //删除活动前的操作
    int deUpdateActivity(Activity activity);
}
